package com.wanmait.hotelManage.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.wanmait.hotelManage.util.DBHelper;
import com.wanmait.hotelManage.vo.Breakfast;

public class BreakfastDAO {
	private BreakfastDAO() {};
	private static BreakfastDAO breakfastdao=new BreakfastDAO();
	public static BreakfastDAO getBreakfastdao() {
		return breakfastdao;
	}
	/**
	 * 查询早餐
	 * @return
	 */
	public Breakfast findall() {
		Breakfast bf=null;
		Connection conn=null;
		PreparedStatement ps=null;
		ResultSet rs=null;
		String sql="select * from breakfast";
		conn=DBHelper.getDBHelper().getConn();
		try {
			ps=conn.prepareStatement(sql);
			rs=ps.executeQuery();
			if(rs.next()) {
				bf=new Breakfast();
				bf.setId(rs.getInt("id"));
				bf.setPrice(rs.getDouble("price"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			DBHelper.getDBHelper().close(rs, ps, conn);
		}
		
		return bf;
	}
//	public static void main(String[] args) {
//		BreakfastDAO.getBreakfastdao().update(1, 40.0);
//	}
	public void update(Integer id, double parseDouble) {
		String sql="update breakfast set price=? where id=?";
		DBHelper.getDBHelper().executeUpdate(sql, parseDouble,id);
	}
	public Double findPrice() {
		Connection conn=null;
		PreparedStatement ps=null;
		ResultSet rs=null;
		String sql="select * from breakfast";
		conn=DBHelper.getDBHelper().getConn();
		try {
			ps=conn.prepareStatement(sql);
			rs=ps.executeQuery();
			if(rs.next()) {
				Double price=rs.getDouble("price");
				return price;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			DBHelper.getDBHelper().close(rs, ps, conn);
		}
		return null;
	}
}
